package com.gzwanchuang.lszg.dialog;

/**
 * 文件名 : HomeFirstDialog
 * 创建者 : MangoWang
 * 创建日期 : 2019/12/8 16:03
 * 微信 : MangoWaWang
 * 邮箱 : 763482205@qq.com
 * 描述 : TODO
 */

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;

import com.gzwanchuang.lszg.R;
import com.gzwanchuang.lszg.help.GlideHelper;

import kale.ui.view.dialog.BaseCustomDialog;
import kale.ui.view.dialog.BaseEasyDialog;
import kale.ui.view.dialog.EasyDialog;

/**
 * Created by AndroidIntexh1 on 2018/9/25.
 */

public class ActionDialog extends BaseCustomDialog {

    public static final String KEY_CONTENT = "KEY_CONTENT";

    /**
     * 继承自{@link EasyDialog.Builder}以扩展builder
     */
    public static class Builder extends BaseEasyDialog.Builder<Builder> {

        private Bundle bundle = new Bundle();

        public Builder(@NonNull Context context) {
            super(context);
        }


        public Builder setContent(String content) {
            bundle.putString(KEY_CONTENT, content);
            return this;
        }

        @NonNull
        @Override
        protected EasyDialog createDialog() {
            ActionDialog dialog = new ActionDialog();
            dialog.setArguments(bundle); // 增加自己的bundle
            return dialog;
        }
    }


    @Override
    protected int getLayoutResId() {
        return R.layout.dialog_action_show;
    }

    @Override
    protected void bindViews(View view) {
        ImageView closeView = findView(R.id.button);
        closeView.setOnClickListener(view1 -> dismiss());
        ImageView signView = findView(R.id.home_first_dialog);
//        signView.loadDataWithBaseURL(null, getArguments().getString(KEY_CONTENT), "text/html", "utf-8", null);
        GlideHelper.INSTANCE.loadImage(signView, getArguments().getString(KEY_CONTENT));
//        signView.setOnClickListener(v -> {
//            dismiss();
//            WebViewActivity.startActivity(getContext(), WebApis.signin);
//        });
    }

    @Override
    protected void setViews() {
        setBackground();
        setLayout();

    }

    /**
     * 强制取消背景，保持有透明
     */
    private void setBackground() {
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable()); // 去除dialog的背景，即透明
//        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(0xffffffff)); // 设置白色背景
//            getDialog().getWindow().setBackgroundDrawableResource(R.drawable.dialog_shop_jion_bg); // 设置背景
    }


    /**
     * 也可通过setLayout来设置：
     * getDialog().getWindow().setLayout(dm.widthPixels, getDialog().getWindow().getAttributes().height);
     */
    private void setLayout() {
        Window window = getDialog().getWindow();
        final WindowManager.LayoutParams lp = window.getAttributes();
        lp.gravity = Gravity.CENTER; // 设置展示的位置
        window.setAttributes(lp);
    }

    @Override
    protected void modifyAlertDialogBuilder(AlertDialog.Builder builder) {
        super.modifyAlertDialogBuilder(builder);
    }
}
